import axios from './axios'
import qs from 'qs'
/**
 * 基类
 *
 * @export
 * @class BaseService
 */
export default class BaseService {
  constructor(url) {
    this.url = url
  }
  // 删除 ids:Array
  delete(params) {
    return axios.delete(`${this.url}/`, params)
  }

  // 插入 entity:Object
  post(params) {
    return axios.post(`${this.url}/`, params)
  }

  // 查询数据 ps p :Object
  select(params) {
    return axios.post(`${this.url}/select/page`, params)
  }

  // 查询数据 ps p :Object
  get(params) {
    return axios({
      method: 'get',
      url: `${this.url}/`,
      data: params
    })
  }

  // 查询数据byId id:number
  id(id) {
    return axios.get(`${this.url}/${id}`)
  }

  // 更新数据 entity: Object
  put(id, params) {
    return axios.put(`${this.url}/${id}`, params, 'JSON')
  }

  excel(params) {
    if (Object.keys(params).length == 0) return axios.get(`${this.url}/excel/page`)
    else return axios.get(`${this.url}/excel/page?${qs.stringify(params, { arrayFormat: 'repeat' })}`)
  }
}